//
//  TwoInputBox.m
//  ArtCircle
//
//  Created by sunbin on 2017/5/18.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "TwoInputBox.h"

@interface TwoInputBox()


@end

@implementation TwoInputBox
{
    UIButton *resendBtn;

}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    
    _account.leftView        = [[LeftView alloc] initWithFrame:CGRectMake(0, 0, 80, 45)];
    _account.leftViewMode    = UITextFieldViewModeAlways;
    
    
    _configBtn.enabled = NO;
    [_configBtn setBackgroundColor:[UIColor grayColor] forState:UIControlStateDisabled];
    [_configBtn setBackgroundColor:[UIColor  redColor] forState:UIControlStateNormal];
    
    
    
    // 倒计时 右侧侧视图
    _pwd.placeholder = @"请输入短信验证码";
    
    resendBtn           = [UIButton buttonWithType:UIButtonTypeCustom];
    resendBtn.tag = 0;

    [resendBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [resendBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    CGFloat height = HEIGHT(_pwd);
    CGFloat width = [@"重新发送(60)" widthWithFont:[UIFont systemFontOfSize:13.f] constrainedToHeight:height];
    
    resendBtn.frame = CGRectMake(0, 0, width, height);

    _pwd.rightView = resendBtn;
    _pwd.rightViewMode = UITextFieldViewModeAlways;
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countDownEen) name:FIRSTTIMECOUBTDOWN object:nil];
}

// 第一次启动倒计时
- (void)countDownEen{

   
    [resendBtn startTime:59 title:@"重新发送(60s)" waitTittle:@"s" respond:^(BOOL isPlayComple) {
        if (isPlayComple) {
            
        }
    }];

}

- (IBAction)btnAction:(UIButton *)sender {
    
    [self endEditing:YES];
    
    if (_nextStepHandler) {
        _nextStepHandler(_account.text ,_pwd.text ,sender.tag ,sender);
    }
    
    
}
- (IBAction)editingChanged:(UITextField *)sender {
    
    _configBtn.enabled = ![_account.text isBlank] && ![_pwd.text isBlank];
    
}



- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    if (![_account.text isBlank] && ![_pwd.text isBlank]) {
        [self btnAction:_configBtn];
    }
    
    return YES;
}







+ (instancetype)twoInputBoxHandle{
    
    TwoInputBox *two = [self  loadFromNib];
    
    
    return two;
    
}



+ (instancetype)loadFromNib{
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"TwoInputBox" owner:nil options:nil];
    return [objects lastObject];
}

@end
